# Name:    CProfile.py
# Date:    Thu Apr  8 22:04:26 CEST 2010
# Purpose: Create and update profile. The profile is often created in the $HOME directory.
# Def:     CProfile(profileDir)
# Inputs:  

import os

# my libraries
from CProcMngr import CProcMngr

####################################################################################################

class CProfile():
	__profileDir = None
	__oProcMngr = None

	__CMD_CREATE_DIR = 'mkdir -p '
	__CMD_REMOVE_DIR = 'rm -rf '
	__CMD_COPY_FILE = 'cp '
	__CMD_COPY_FILE_FORCE = 'cp -r '

#---------------------------------------------------------------------------------------------------

	def __init__(self, profileDir):
		self.__profileDir = profileDir
		self.__oProcMngr = CProcMngr()

#---------------------------------------------------------------------------------------------------

	def createProfile(self):
		self.__oProcMngr.execCmd(self.__CMD_CREATE_DIR + self.__profileDir)

#---------------------------------------------------------------------------------------------------

	def deleteProfile(self):
		self.__oProcMngr.execCmd(self.__CMD_REMOVE_DIR + self.__profileDir)

#---------------------------------------------------------------------------------------------------

	def addFile(self, file, overWrite = False):
		filePath = self.__profileDir + '/' + os.path.basename(file)

		# TODO: exception if 'file' does not exist
		if overWrite is True:
			self.__oProcMngr.execCmd(self.__CMD_COPY_FILE + file + ' ' + self.__profileDir)
		else:
			if os.path.exists(filePath) is False:
				self.__oProcMngr.execCmd(self.__CMD_COPY_FILE + file + ' ' + self.__profileDir)
				
		
####################################################################################################
